<html lang="en-US">

<head>
    
<title>Grafana&#43;Loki搭建日志系统 - 花落雨忧</title>

<meta property="og:title" content="Grafana&#43;Loki搭建日志系统 - 花落雨忧">



    



    
    <meta property="description" content="1.构建docker-compose.yaml文件
[&amp;hellip;] version: &amp;#34;3&amp;#34; services: # Loki 日志搜集 loki: image: grafana/loki:2.4.1 container_name: grafana_loki depends_on: - tempo ports: - &amp;#34;31000:3100&amp;#34; volumes: &amp;hellip;">
    <meta property="og:description" content="1.构建docker-compose.yaml文件
[&amp;hellip;] version: &amp;#34;3&amp;#34; services: # Loki 日志搜集 loki: image: grafana/loki:2.4.1 container_name: grafana_loki depends_on: - tempo ports: - &amp;#34;31000:3100&amp;#34; volumes: &amp;hellip;">
    






<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1">

<link rel="shortcut icon" href="https://www.lican.asia/logo/logo.png" type="image/x-icon" />



<link rel="stylesheet" href="/css/style.min.css" />

<link rel="stylesheet" href="/css/reset.min.css" />




<script src="https://www.lican.asia/js/highlight.min.js"></script>

<script>
hljs.configure({ ignoreUnescapedHTML: true })
hljs.highlightAll();
</script>


<script src="https://www.lican.asia/js/jquery.min.js"></script>




<link href="https://www.lican.asia/css/hugo-code.min.css" rel="stylesheet" />



    <style>
        .post-content img {
            max-width: 400px;
        }
    </style>
</head>

<body id="period" class="home blog">
    <a class="skip-content" href="#main">Press "Enter" to skip to content</a>
    <div id="overflow-container" class="overflow-container">
        <header class="site-header" id="site-header" role="banner">
    <div class="max-width">
        <div id="title-container" class="title-container">
            <div id="site-title" class="site-title"><a href="/">花落雨忧</a></div>
            <p class="tagline">思所及 力所行 方为真.</p>
        </div>
        
        <div id="menu-primary-container" class="menu-primary-container">
            <div class="icon-container">
            </div>
            <div id="menu-primary" class="menu-container menu-primary" role="navigation">
                <nav class="menu">
                    <ul id="menu-primary-items" class="menu-primary-items">
                        
                        
                        <li id="menu-item-0"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/posts" aria-current="page" tabindex="0">首页</a></li>
                        
                        <li id="menu-item-1"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/tech/" aria-current="page" tabindex="1">技术文档</a></li>
                        
                        <li id="menu-item-2"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/article/" aria-current="page" tabindex="2">文章</a></li>
                        
                        <li id="menu-item-3"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/project/" aria-current="page" tabindex="3">项目</a></li>
                        
                        <li id="menu-item-4"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/about/" aria-current="page" tabindex="4">关于</a></li>
                        
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</header>

        <div id="primary-container" class="primary-container">
            <div class="max-width">
                <section id="main" class="main" role="main">
                    <div id="loop-container" class="loop-container">
                        <div
                            class="post type-post status-publish format-standard hentry entry">
                            <article>
                                <div class="post-container">
                                    <div class="post-header">
                                        <h2 class="post-title">
                                            <a href="/posts/grafana&#43;loki%E6%90%AD%E5%BB%BA%E6%97%A5%E5%BF%97%E7%B3%BB%E7%BB%9F/">Grafana&#43;Loki搭建日志系统</a>
                                        </h2>
                                        
                                        <div class="post-byline">Published on
                                            <a class="date" href="javascript:;">2025/03/18</a>
                                            
                                            
                                            
                                            
                                            
                                        
                                    </div>
                                    <div class="post-content">
                                        <h3 id="grafanaloki搭建日志系统">Grafana+Loki搭建日志系统</h3>
<h3 id="背景-之前搭建过elasticsearchkibanafilebeat的日志系统由于日志存储的位置是动态的filebeat采集目录需要对应更换当执行dockerc-compose-downdocker-compose-up原容器id会变存储的目录也会变所以觉得实用性不大所以使用grafanaloki搭建日志系统将容器的日志推送到loki上然后使用grafana配置loki数据源即可">背景： 之前搭建过elasticsearch+kibana+filebeat的日志系统，由于日志存储的位置是动态的，filebeat采集目录需要对应更换，当执行dockerc-compose down;docker-compose up;原容器ID会变，存储的目录也会变，所以觉得实用性不大。所以使用grafana+loki搭建日志系统，将容器的日志推送到loki上，然后使用grafana配置loki数据源即可~</h3>
<p>1.构建docker-compose.yaml文件</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">version</span>: <span style="color:#e6db74">&#34;3&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">services</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Loki</span> <span style="color:#a6e22e">日志搜集</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">loki</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span>:<span style="color:#ae81ff">2.4.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">grafana_loki</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">depends_on</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">tempo</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;31000:3100&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">/</span><span style="color:#a6e22e">etc</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">etc</span><span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">environment</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">JAEGER_AGENT_HOST</span>=<span style="color:#a6e22e">tempo</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">JAEGER_ENDPOINT</span>=<span style="color:#a6e22e">http</span>:<span style="color:#75715e">//tempo:14268/api/traces # send traces to Tempo
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">JAEGER_SAMPLER_TYPE</span>=<span style="color:#66d9ef">const</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">JAEGER_SAMPLER_PARAM</span>=<span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#e6db74">&#34;always&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Promtail</span> <span style="color:#a6e22e">日志搜集</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">promtail</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span>:<span style="color:#ae81ff">2.4.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">grafana_promtail</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#e6db74">&#34;always&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#f92672">/</span><span style="color:#66d9ef">var</span><span style="color:#f92672">/</span><span style="color:#a6e22e">log</span>:<span style="color:#f92672">/</span><span style="color:#66d9ef">var</span><span style="color:#f92672">/</span><span style="color:#a6e22e">log</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span><span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span><span style="color:#f92672">-</span><span style="color:#a6e22e">config</span>.<span style="color:#a6e22e">yaml</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">etc</span><span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span><span style="color:#f92672">/</span><span style="color:#a6e22e">config</span>.<span style="color:#a6e22e">yaml</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">command</span>: <span style="color:#f92672">-</span><span style="color:#a6e22e">config</span>.<span style="color:#a6e22e">file</span>=<span style="color:#f92672">/</span><span style="color:#a6e22e">etc</span><span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span><span style="color:#f92672">/</span><span style="color:#a6e22e">config</span>.<span style="color:#a6e22e">yaml</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Tempo</span> <span style="color:#a6e22e">日志追踪</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">tempo</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">tempo</span>:<span style="color:#ae81ff">1.2.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">command</span>: [<span style="color:#e6db74">&#34;-config.file=/etc/tempo.yaml&#34;</span>]
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">grafana_tempo</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">tempo</span><span style="color:#f92672">/</span><span style="color:#a6e22e">tempo</span><span style="color:#f92672">-</span><span style="color:#a6e22e">local</span>.<span style="color:#a6e22e">yaml</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">etc</span><span style="color:#f92672">/</span><span style="color:#a6e22e">tempo</span>.<span style="color:#a6e22e">yaml</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;14268:14268&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">jaeger</span> <span style="color:#a6e22e">ingest</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;3200:3200&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">tempo</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;55680&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">otlp</span> <span style="color:#a6e22e">grpc</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;55681&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">otlp</span> <span style="color:#a6e22e">http</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;9411&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">zipkin</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#e6db74">&#34;always&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Grafana</span> <span style="color:#a6e22e">界面查看</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">grafana</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">grafana</span>:<span style="color:#ae81ff">8.2.6</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;30000:3000&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">data</span>:<span style="color:#f92672">/</span><span style="color:#66d9ef">var</span><span style="color:#f92672">/</span><span style="color:#a6e22e">lib</span><span style="color:#f92672">/</span><span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">conf</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">usr</span><span style="color:#f92672">/</span><span style="color:#a6e22e">share</span><span style="color:#f92672">/</span><span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">conf</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#e6db74">&#34;always&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Prometheus</span> <span style="color:#a6e22e">指标监控</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">prometheus</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">prom</span><span style="color:#f92672">/</span><span style="color:#a6e22e">prometheus</span>:<span style="color:#a6e22e">v2</span><span style="color:#ae81ff">.31.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#e6db74">&#34;prometheus&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;9090:9090&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#a6e22e">always</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">站点监控</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">blackbox</span><span style="color:#f92672">-</span><span style="color:#a6e22e">exporter</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">prom</span><span style="color:#f92672">/</span><span style="color:#a6e22e">blackbox</span><span style="color:#f92672">-</span><span style="color:#a6e22e">exporter</span>:<span style="color:#a6e22e">v0</span><span style="color:#ae81ff">.19.0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#e6db74">&#34;blackbox_exporter&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;9115:9115&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;./blackbox_exporter/config.yml:/etc/blackbox_exporter/config.yml&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">grafana</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#a6e22e">always</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">系统监控</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">node_exporter</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">prom</span><span style="color:#f92672">/</span><span style="color:#a6e22e">node</span><span style="color:#f92672">-</span><span style="color:#a6e22e">exporter</span>:<span style="color:#a6e22e">v1</span><span style="color:#ae81ff">.3.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#a6e22e">node_exporter</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">command</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;--path.rootfs=/host&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">network_mode</span>: <span style="color:#a6e22e">host</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">pid</span>: <span style="color:#a6e22e">host</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#a6e22e">unless</span><span style="color:#f92672">-</span><span style="color:#a6e22e">stopped</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#e6db74">&#34;/:/host:ro,rslave&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">grafana</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">external</span>: <span style="color:#66d9ef">true</span>
</span></span></code></pre></div><p>启动时，某些容器会失败，原因是配置文件没加载，针对上述容器，我们列举配置文件</p>
<p><img src="https://www.lican.asia/images/grafana/1742282284601.png" alt="1742282284601"></p>
<ul>
<li>
<p>blackbox_exporter文件夹下面config.yml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">modules</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">http_2xx</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">http</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">http_post_2xx</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">http</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">http</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">method</span>: <span style="color:#a6e22e">POST</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">tcp_connect</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">tcp</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">tls_connect</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">tcp</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">timeout</span>: <span style="color:#ae81ff">5</span><span style="color:#a6e22e">s</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">tcp</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">tls</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">tls_config</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">insecure_skip_verify</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">pop3s_banner</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">tcp</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">tcp</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">query_response</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">expect</span>: <span style="color:#e6db74">&#34;^+OK&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">tls</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">tls_config</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">insecure_skip_verify</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">ssh_banner</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">tcp</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">tcp</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">query_response</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">expect</span>: <span style="color:#e6db74">&#34;^SSH-2.0-&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">send</span>: <span style="color:#e6db74">&#34;SSH-2.0-blackbox-ssh-check&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">irc_banner</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">tcp</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">tcp</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">query_response</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">send</span>: <span style="color:#e6db74">&#34;NICK prober&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">send</span>: <span style="color:#e6db74">&#34;USER prober prober prober :prober&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">expect</span>: <span style="color:#e6db74">&#34;PING :([^ ]+)&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">send</span>: <span style="color:#e6db74">&#34;PONG ${1}&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">expect</span>: <span style="color:#e6db74">&#34;^:[^ ]+ 001&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">icmp</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">prober</span>: <span style="color:#a6e22e">icmp</span>
</span></span></code></pre></div><ul>
<li>
<p>loki目录下 loki/etc/local-config.yaml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">auth_enabled</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">server</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">http_listen_port</span>: <span style="color:#ae81ff">3100</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">common</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">path_prefix</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">storage</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">filesystem</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">chunks_directory</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">/</span><span style="color:#a6e22e">chunks</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">rules_directory</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">/</span><span style="color:#a6e22e">rules</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">replication_factor</span>: <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">ring</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">instance_addr</span>: <span style="color:#ae81ff">127.0.0.1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">kvstore</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">store</span>: <span style="color:#a6e22e">inmemory</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">schema_config</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">configs</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">-</span> <span style="color:#a6e22e">from</span>: <span style="color:#ae81ff">2020</span><span style="color:#f92672">-</span><span style="color:#ae81ff">10</span><span style="color:#f92672">-</span><span style="color:#ae81ff">24</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">store</span>: <span style="color:#a6e22e">boltdb</span><span style="color:#f92672">-</span><span style="color:#a6e22e">shipper</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">object_store</span>: <span style="color:#a6e22e">filesystem</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">schema</span>: <span style="color:#a6e22e">v11</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">index</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">prefix</span>: <span style="color:#a6e22e">index_</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">period</span>: <span style="color:#ae81ff">24</span><span style="color:#a6e22e">h</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ruler</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">alertmanager_url</span>: <span style="color:#a6e22e">http</span>:<span style="color:#75715e">//localhost:9093
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#a6e22e">storage_config</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">boltdb</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">directory</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">tmp</span><span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">/</span><span style="color:#a6e22e">index</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">filesystem</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">directory</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">tmp</span><span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">/</span><span style="color:#a6e22e">chunks</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">limits_config</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">enforce_metric_name</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">reject_old_samples</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">reject_old_samples_max_age</span>: <span style="color:#ae81ff">168</span><span style="color:#a6e22e">h</span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">表的保留期7天</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">table_manager</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">retention_deletes_enabled</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">retention_period</span>: <span style="color:#ae81ff">168</span><span style="color:#a6e22e">h</span>
</span></span></code></pre></div></li>
<li>
<p>promtail目录下的promtail-config.yaml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">server</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">http_listen_port</span>: <span style="color:#ae81ff">9080</span>      <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Promtail</span> <span style="color:#a6e22e">HTTP</span> <span style="color:#a6e22e">监听端口</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">grpc_listen_port</span>: <span style="color:#ae81ff">9095</span>       <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">Promtail</span> <span style="color:#a6e22e">gRPC</span> <span style="color:#a6e22e">监听端口</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">positions</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">filename</span>: <span style="color:#f92672">/</span><span style="color:#66d9ef">var</span><span style="color:#f92672">/</span><span style="color:#a6e22e">promtail</span><span style="color:#f92672">/</span><span style="color:#a6e22e">positions</span>.<span style="color:#a6e22e">yaml</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">存储日志位置文件的路径</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">clients</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">-</span> <span style="color:#a6e22e">url</span>: <span style="color:#a6e22e">http</span>:<span style="color:#75715e">//loki:3100/loki/api/v1/push  # Loki 的推送端点
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">scrape_configs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">-</span> <span style="color:#a6e22e">job_name</span>: <span style="color:#a6e22e">system_logs</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">作业名称</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">static_configs</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">targets</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">-</span> <span style="color:#a6e22e">localhost</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">目标地址</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">labels</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">job</span>: <span style="color:#a6e22e">varlogs</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">标签</span>
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">__path__</span>: <span style="color:#f92672">/</span><span style="color:#66d9ef">var</span><span style="color:#f92672">/</span><span style="color:#a6e22e">log</span><span style="color:#f92672">/*</span>.<span style="color:#a6e22e">log</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">要抓取的日志路径</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">-</span> <span style="color:#a6e22e">job_name</span>: <span style="color:#a6e22e">container_logs</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">另一作业名称</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">适用于</span> <span style="color:#a6e22e">Docker</span> <span style="color:#a6e22e">容器日志</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">pipeline_stages</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">docker</span>: {}  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">处理</span> <span style="color:#a6e22e">Docker</span> <span style="color:#a6e22e">格式的日志</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">kubernetes_sd_configs</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">role</span>: <span style="color:#a6e22e">pod</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">从</span> <span style="color:#a6e22e">Kubernetes</span> <span style="color:#a6e22e">中获取</span> <span style="color:#a6e22e">Pod</span> <span style="color:#a6e22e">日志</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">relabel_configs</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">source_labels</span>: [<span style="color:#a6e22e">__meta_kubernetes_namespace</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">action</span>: <span style="color:#a6e22e">replace</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">target_label</span>: <span style="color:#a6e22e">namespace</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">source_labels</span>: [<span style="color:#a6e22e">__meta_kubernetes_pod_name</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">action</span>: <span style="color:#a6e22e">replace</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">target_label</span>: <span style="color:#a6e22e">pod</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">source_labels</span>: [<span style="color:#a6e22e">__meta_kubernetes_container_name</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">action</span>: <span style="color:#a6e22e">replace</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">target_label</span>: <span style="color:#a6e22e">container</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">source_labels</span>: [<span style="color:#a6e22e">__address__</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">action</span>: <span style="color:#a6e22e">replace</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">target_label</span>: <span style="color:#a6e22e">__host__</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">replacement</span>: <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">用于替换的地址</span>
</span></span></code></pre></div></li>
<li>
<p>tempo文件夹下的tempo-local.yaml</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">tempo</span>.<span style="color:#a6e22e">yaml</span> <span style="color:#a6e22e">最小化可用配置</span> <span style="color:#a6e22e">v1</span><span style="color:#ae81ff">.2.1</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">server</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">http_listen_port</span>: <span style="color:#ae81ff">3200</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">默认HTTP端口</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">distributor</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">receivers</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">otlp</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">protocols</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">grpc</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">4317</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">http</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">4318</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">jaeger</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">protocols</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">thrift_http</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">14268</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">grpc</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">14250</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">thrift_binary</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">6832</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">thrift_compact</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">6831</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">zipkin</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">endpoint</span>: <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">9411</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">ring</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">kvstore</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">store</span>: <span style="color:#a6e22e">memberlist</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">使用内置的memberlist集群</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ingester</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">lifecycler</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ring</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">kvstore</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">store</span>: <span style="color:#a6e22e">memberlist</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">replication_factor</span>: <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">final_sleep</span>: <span style="color:#ae81ff">0</span><span style="color:#a6e22e">s</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">trace_idle_period</span>: <span style="color:#ae81ff">10</span><span style="color:#a6e22e">s</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">跟踪空闲时间</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">max_block_bytes</span>: <span style="color:#ae81ff">100_000_000</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">每个块的最大大小</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">max_block_duration</span>: <span style="color:#ae81ff">5</span><span style="color:#a6e22e">m</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">storage</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">trace</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">backend</span>: <span style="color:#a6e22e">local</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">local</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">path</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">tmp</span><span style="color:#f92672">/</span><span style="color:#a6e22e">tempo</span><span style="color:#f92672">/</span><span style="color:#a6e22e">blocks</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">pool</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">max_workers</span>: <span style="color:#ae81ff">100</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">queue_depth</span>: <span style="color:#ae81ff">1000</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">compactor</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">compaction</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">block_retention</span>: <span style="color:#ae81ff">24</span><span style="color:#a6e22e">h</span>   <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">块保留时间</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">compaction_window</span>: <span style="color:#ae81ff">1</span><span style="color:#a6e22e">h</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">压缩时间窗口</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">querier</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">frontend_worker</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">frontend_address</span>: <span style="color:#ae81ff">127.0.0.1</span>:<span style="color:#ae81ff">9095</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">query_frontend</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">log_queries_longer_than</span>: <span style="color:#ae81ff">5</span><span style="color:#a6e22e">s</span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">如果需启用</span> <span style="color:#a6e22e">Jaeger</span> <span style="color:#a6e22e">搜索</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">改为配置</span> <span style="color:#a6e22e">jaeger_query</span> <span style="color:#a6e22e">部分</span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span><span style="color:#a6e22e">jaeger_query</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span>  <span style="color:#a6e22e">enabled</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">#</span>  <span style="color:#a6e22e">http_prefix</span>: <span style="color:#e6db74">&#34;/jaeger&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">memberlist</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">join_members</span>: []  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">单节点模式</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">集群模式需配置节点列表</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">bind_port</span>: <span style="color:#ae81ff">7946</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">multitenancy_enabled</span>: <span style="color:#66d9ef">false</span>  <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">是否启用多租户</span>
</span></span></code></pre></div></li>
</ul>
</li>
</ul>
<p>2.然后执行docker-compose down;docker-compose up -d; 即可运行</p>
<p><img src="https://www.lican.asia/images/grafana/1742289481795.png" alt="1742289481795"></p>
<p>3.开放服务器安全组的30000端口，然后在浏览器访问ip:30000 ， 即可打开grafana【第一次登陆的账号和密码均为admin】</p>
<p><img src="https://www.lican.asia/images/grafana/1742289579189.png" alt="1742289579189"></p>
<p>4.配置数据源</p>
<p>在grafana侧边菜单点击Configuration-&gt;Data Source-&gt;Add data source搜索并选择Loki</p>
<p><img src="https://www.lican.asia/images/grafana/1742289731376.png" alt="1742289731376"></p>
<p>配置Loki地址</p>
<p><img src="https://www.lican.asia/images/grafana/1742289881676.png" alt="1742289881676"></p>
<p><img src="https://www.lican.asia/images/grafana/1742289907163.png" alt="1742289907163"></p>
<p>5.容器日志推送至Loki</p>
<ul>
<li>
<p>安装Loki插件【多试几次】</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">docker</span> <span style="color:#a6e22e">plugin</span> <span style="color:#a6e22e">install</span> <span style="color:#a6e22e">grafana</span><span style="color:#f92672">/</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">-</span><span style="color:#a6e22e">docker</span><span style="color:#f92672">-</span><span style="color:#a6e22e">driver</span>:<span style="color:#a6e22e">latest</span> <span style="color:#f92672">--</span><span style="color:#a6e22e">alias</span> <span style="color:#a6e22e">loki</span> <span style="color:#f92672">--</span><span style="color:#a6e22e">grant</span><span style="color:#f92672">-</span><span style="color:#a6e22e">all</span><span style="color:#f92672">-</span><span style="color:#a6e22e">permissions</span>
</span></span></code></pre></div><p><img src="https://www.lican.asia/images/grafana/1742291094453.png" alt="1742291094453"></p>
</li>
<li>
<p>容器配置推送</p>
<p>在任意服务器上【前提是安装了Loki插件，且能访问目标服务器的Loki地址】配置</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#a6e22e">x</span><span style="color:#f92672">-</span><span style="color:#a6e22e">logging</span>: <span style="color:#f92672">&amp;</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">-</span><span style="color:#a6e22e">logging</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">driver</span>: <span style="color:#a6e22e">loki</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">options</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">loki</span><span style="color:#f92672">-</span><span style="color:#a6e22e">url</span>: <span style="color:#e6db74">&#34;http://120.77.213.80:31000/loki/api/v1/push&#34;</span> <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">grafana和Loki目标服务</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">max</span><span style="color:#f92672">-</span><span style="color:#a6e22e">size</span>: <span style="color:#e6db74">&#34;10m&#34;</span>          <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">每个日志文件的最大大小</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">max</span><span style="color:#f92672">-</span><span style="color:#a6e22e">file</span>: <span style="color:#e6db74">&#34;3&#34;</span>            <span style="color:#960050;background-color:#1e0010">#</span> <span style="color:#a6e22e">保留的日志文件最大数量</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span>  <span style="color:#a6e22e">brewing</span><span style="color:#f92672">-</span><span style="color:#a6e22e">bigdata</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">image</span>: <span style="color:#a6e22e">golang</span>:<span style="color:#ae81ff">1.15</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">container_name</span>: <span style="color:#e6db74">&#34;soa_brewing_bigdata&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ports</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#ae81ff">30013</span>:<span style="color:#ae81ff">30013</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">volumes</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">brewing</span><span style="color:#f92672">-</span><span style="color:#a6e22e">bigdata</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">app</span><span style="color:#f92672">/</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> .<span style="color:#f92672">/</span><span style="color:#a6e22e">logs</span>:<span style="color:#f92672">/</span><span style="color:#a6e22e">app</span><span style="color:#f92672">/</span><span style="color:#a6e22e">logs</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">working_dir</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">app</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">command</span>: <span style="color:#f92672">/</span><span style="color:#a6e22e">app</span><span style="color:#f92672">/</span><span style="color:#a6e22e">brewing_bigdata_app</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">restart</span>: <span style="color:#e6db74">&#34;always&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">environment</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">TZ</span>=<span style="color:#a6e22e">Asia</span><span style="color:#f92672">/</span><span style="color:#a6e22e">Shanghai</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">networks</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">-</span> <span style="color:#a6e22e">nbi</span><span style="color:#f92672">-</span><span style="color:#a6e22e">net</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">logging</span>: <span style="color:#f92672">*</span><span style="color:#a6e22e">loki</span><span style="color:#f92672">-</span><span style="color:#a6e22e">logging</span>
</span></span></code></pre></div><p><img src="https://www.lican.asia/images/grafana/1742291362542.png" alt="1742291362542"></p>
<p><img src="https://www.lican.asia/images/grafana/1742291303744.png" alt="1742291303744"></p>
</li>
</ul>
<p>6.搜索日志</p>
<p>点击grafana的侧边栏的Explore</p>
<p>点击Log browser选择容器-&gt;Show logs</p>
<p><img src="https://www.lican.asia/images/grafana/1742290007370.png" alt="1742290007370"></p>
<p>注意：grafana的语法比较特殊，这里给出两个示例</p>
<p>搜索brewing容器下，过滤354e8706299d0002 和 1430422b99f755890ed3dffa68b392b5</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span>{<span style="color:#a6e22e">container_name</span>=<span style="color:#e6db74">&#34;brewing&#34;</span>} <span style="color:#f92672">|=</span> <span style="color:#e6db74">&#34;354e8706299d0002&#34;</span> <span style="color:#f92672">|=</span> <span style="color:#e6db74">&#34;1430422b99f755890ed3dffa68b392b5&#34;</span>
</span></span></code></pre></div><p><img src="https://www.lican.asia/images/grafana/1742290216603.png" alt="1742290216603"></p>
<p>搜索brewing容器下，过滤354e8706299d0002 或 354ea893b2fa0001</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span>{<span style="color:#a6e22e">container_name</span>=<span style="color:#e6db74">&#34;brewing&#34;</span>} |~ <span style="color:#e6db74">&#34;354e8706299d0002|354ea893b2fa0001&#34;</span>
</span></span></code></pre></div><p><img src="https://www.lican.asia/images/grafana/1742290868347.png" alt="1742290868347"></p>
<p>eg: 例如我们要将A服务器上容器日志推送到B服务器上的Loki上， 需要在A服务器上安装Loki插件，且配置容器docker-compose.yml文件的loki地址</p>
<p><a href="https://pan.baidu.com/s/1wZLxXAWZ3wUu4SMULxuT0Q?pwd=2kzu">Grafana安装包</a></p>


                                        
                                        
                                        
                                        
                                    </div>

                                    
                                    
                                    

                                    
                                    <div class="post-meta">
                                        
                                        
                                        
                                        <nav class="further-reading">
                                            
                                            <div class="previous">
                                                <span>&lt;&lt; Prev</span>
                                                <a href="https://www.lican.asia/tech/grafana&#43;loki%E6%90%AD%E5%BB%BA%E6%97%A5%E5%BF%97%E7%B3%BB%E7%BB%9F/"
                                                    rel="prev">Grafana&#43;Loki搭建日志系统</a> </div>
                                            
                                            
                                            <div class="next">
                                                <span>Next >></span>
                                                <a href="https://www.lican.asia/tech/k8s%E5%AE%89%E8%A3%85/">K8s安装</a> 
                                            </div>
                                            
                                        </nav>
                                    </div>
                                    
                                    

                                    
                                    
                                    

                                </div>
                            </article>
                        </div>
                    </div>
                </section>
                <aside class="sidebar sidebar-primary" id="sidebar-primary" role="complementary">
    <h1 class="screen-reader-text">Sidebar</h1>
    

    
    
    <section id="text-2" class="widget widget_text">
        <div class="textwidget">
            
            <div id="profile">
                <div id="profile_picture"><img src="https://www.lican.asia/logo/logo.png"></div>
                <div id="profile_intro">
                    <p><span class="name">Lican</span></p>
                    <p class="intro">全栈开发者，爱好造轮子。</p>
                </div>
            </div>
            
            <p>
                <script type="text/javascript">
                    (function ($) {
                        $(document).ready(function () {
                            var menuPrimaryContainer = $('#menu-primary-container');
                            var profile = $('#text-2');
                            $('#toggle-navigation').click(function () {
                                if (menuPrimaryContainer.hasClass('open')) {
                                    profile.removeClass('open');
                                } else {
                                    profile.addClass('open');
                                }
                            });
                        });
                    })(jQuery);
                </script>
            </p>
        </div>
    </section>
    
    
    
    
    
    <section id="text-5" class="widget widget_text">
        <h2 class="widget-title">开源项目</h2>
        <div class="textwidget">
            <div id="projects" style="line-height: 22px;">
                
                <a href="https://github.com/idoubi/gonews"
                    target="_blank">gonews</a>: &nbsp;Daily news for golang<br>
                
                <a href="https://github.com/idoubi/sql2struct"
                    target="_blank">sql2struct</a>: &nbsp;Generate go struct according to SQL<br>
                
                <a href="https://github.com/idoubi/goz"
                    target="_blank">goz</a>: &nbsp;Request library used in golang<br>
                
        </div>
    </section>
    
    

    
    
    
    
    <section id="qrcode" class="widget widget_media_image">
        <h2 class="widget-title">微信公众号</h2>
        <img width="258" height="258"
            src="https://www.lican.asia/wechat/lican.png"
            class="image wp-image-5514  attachment-full size-full" alt=""
            style="max-width: 100%; height: auto;"
            sizes="(max-width: 258px) 100vw, 258px">
    </section>
    
    

    
    
    

    
    
    

    
    
    
    
</aside>
            </div>
        </div>

        <footer id="site-footer" class="site-footer" role="contentinfo">
    <div class="max-width">
    </div>
    <div class="footer">
        <div id="footercontent">
            © lican.asia All rights reserved<br/>
            Built with Hugo Theme <a href="https://github.com/idoubi/hugo-theme-period" target="_blank">Period</a>
        </div>
    </div>
</footer>

<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?e8351b6d4626d5881d439ea1f6184baa";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
</script>
    
    
    </div>
    
</body>

</html>